<?php
//$datax = array(3.5,3.7,3,4,6.2,6,3.5,8,14,8,11.1,13.7);
//$datay = array(20,22,12,13,17,20,16,19,30,31,40,43);

require_once('C:/Apache/php/ext/jpgraph/src/jpgraph.php');
require_once('C:/Apache/php/ext/jpgraph/src/jpgraph_scatter.php');

// get generations
$ini_array = parse_ini_file("generations.ini", true);
$data = $ini_array["data"];
// get generation index
$genIndex = $_GET["gen"];
// get generation key
$genKey = "generation_".$genIndex;
$generationData = $data[$genKey];
$json = preg_replace('/(?<!")(?<!\w)(\w+)(?!")(?!\w)/', '"$1"', $generationData);
$generation = json_decode($json, true);

$datay = array_keys($generation);
$datax = array();
$inds = count($generation);
$i = 0;
foreach($datay as $key)
{
	$val = $generation[$key];
	$datax[$i] = $val;
	$i++;
}

//$datax = array(3.5,3.7,3,4,6.2,6,3.5,8,14,8,11.1,13.7);
//$datay = array(20,22,12,13,17,20,16,19,30,31,40,43);

$graph = new Graph(600,400);
$graph->SetScale("linlin");

$graph->img->SetMargin(40,40,40,40);        
$graph->SetShadow();
 
$graph->title->Set("Generation ".$genIndex);
$graph->title->SetFont(FF_FONT1,FS_BOLD);
 
$sp1 = new ScatterPlot($datax,$datay);
 
$graph->Add($sp1);
$graph->Stroke();
?>
